﻿namespace NJQuery {
	using System;
	using System.ComponentModel;

	/// <summary>
	/// Server control used to define the properties of a <see href="http://docs.jquery.com/UI/Effects/Explode">jQuery UI Explode effect</see>, which explodes the element into multiple pieces.
	/// </summary>
	public class ExplodeEffect : EffectBase {


		#region Constants: Property defaults

		private const int defaultNumber = 9;

		#endregion


		#region Constructors

		/// <summary>
		/// Initializes a new instance of the <see cref="ExplodeEffect" /> class.
		/// </summary>
		public ExplodeEffect() : base("explode") { }

		#endregion


		#region Properties: Initialization options

		/// <summary>
		/// Number of pieces to be exploded to/imploded from.
		/// This property maps directly to the "number" option when the jQuery UI effect is initialized.
		/// </summary>
		//TODO: This property is silly.  Validate it.  Talk to TheMuuj about it.....
		public virtual int Number {
			get { return ViewState["Number"] as int? ?? defaultNumber; }
			set { ViewState["Number"] = value; }
		}

		#endregion


		#region Methods: Rendering hooks

		/// <summary>
		/// Allows a jQuery server control to reference scripts and stylesheets necessary to render their client markup and widgets.
		/// </summary>
		/// <param name="manager">The <see cref="Manager"/> used to handle style and script referencing in addition to unified generation of load and ready scripts.</param>
		protected override void Register(Manager manager) {
			base.Register(manager);

			manager.RegisterClientScript(ClientScript.UIExplodeEffect);
		}

		/// <summary>
		/// Returns a <see cref="PropertyCollection"/> containing option values specific to the effect.
		/// This method is used primarily by control developers.
		/// </summary>
		/// <returns>A <see cref="PropertyCollection"/> containing the effect's option values.</returns>
		protected override PropertyCollection CreateOptionProperties() {
			PropertyCollection properties = base.CreateOptionProperties();

			int number = Number;
			if(number != defaultNumber) properties.AddValue("number", number);

			return properties;
		}

		#endregion


	}

}